package com.example.healthmanagement.controller;


import com.example.healthmanagement.entity.FoodRem;
import com.example.healthmanagement.entity.HealthAnalysize;
import com.example.healthmanagement.entity.vo.FoodRemVo;
import com.example.healthmanagement.entity.vo.HealthAnaVo;
import com.example.healthmanagement.pojo.AnalyzePojo;
import com.example.healthmanagement.service.FoodRemService;
import com.example.healthmanagement.service.HealthAnaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@RestController
@RequestMapping("/health_ana")
public class HealthAnaController {

    @Autowired
    HealthAnaService service;

    @GetMapping("")
    public List<HealthAnaVo> getAll(String name) {
        return service.findAll(name);
    }

    @PostMapping("")
    public boolean save(@RequestBody HealthAnalysize data) {
        data.setCreatedAt(LocalDateTime.now());
        data.setDeleted(false);
        return service.add(data);
    }

    @PutMapping("")
    public boolean updateCookBook(@RequestBody HealthAnalysize data) {
        return service.update(data);
    }

    @DeleteMapping("/{id}")
    public boolean deleteCookBook(@PathVariable("id") int id) {
        HealthAnalysize data = service.findById(id);
        data.setDeleted(true);
        return service.update(data);
    }

    @PostMapping("/analyze")
    public HealthAnalysize analyze(@RequestBody AnalyzePojo data) {
        HealthAnalysize analyze = service.analyze(data);
        if (analyze == null) {
            return new HealthAnalysize();
        }
        return analyze;
    }
}
